package co.com.smart.eagle.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;


/**
 * The persistent class for the menu database table.
 * 
 */
@Entity
@Table(name="menu")
@NamedQuery(name="EagleSecurityMenu.findAll", query="SELECT w FROM EagleSecurityMenu w")
public class EagleSecurityMenu implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="idmenu")
	private Long idmenu;

	@Column(name="menu_descripcion")
	private String menuDescripcion;

	@Column(name="sequence_rol")
	private BigDecimal sequenceRol;

	@Column(name="type_nodo")
	private String tipoNodo;

	//bi-directional many-to-one association to WlsSecurityResource
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="idresource")
	private EagleSecurityResources wlsSecurityResource;

	//bi-directional many-to-one association to WlsSecurityMenusXMenu
	@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
	private List<EagleSecurityMenusXMenu> children;

	@Column(name="idmenufather")
	private Long idParent;

	public Long getIdParent() {
		return idParent;
	}

	public void setIdParent(Long idParent) {
		this.idParent = idParent;
	}

	//bi-directional many-to-one association to WlsSecurityMenusXMenu
	@OneToMany(mappedBy="child")
	@Cascade({CascadeType.MERGE})
	private List<EagleSecurityMenusXMenu> parents;

	public EagleSecurityMenu() {
	}

	public Long getIdmenu() {
		return this.idmenu;
	}

	public void setIdmenu(Long idmenu) {
		this.idmenu = idmenu;
	}

	public String getMenuDescripcion() {
		return this.menuDescripcion;
	}

	public void setMenuDescripcion(String menuDescripcion) {
		this.menuDescripcion = menuDescripcion;
	}

	public BigDecimal getSequenceRol() {
		return this.sequenceRol;
	}

	public void setSequenceRol(BigDecimal sequenceRol) {
		this.sequenceRol = sequenceRol;
	}

	public String getTipoNodo() {
		return this.tipoNodo;
	}

	public void setTipoNodo(String tipoNodo) {
		this.tipoNodo = tipoNodo;
	}

	public EagleSecurityResources getWlsSecurityResource() {
		return this.wlsSecurityResource;
	}

	public void setWlsSecurityResource(EagleSecurityResources wlsSecurityResource) {
		this.wlsSecurityResource = wlsSecurityResource;
	}


	public List<EagleSecurityMenusXMenu> getChildren() {
		return children;
	}

	public void setChildren(List<EagleSecurityMenusXMenu> children) {
		this.children = children;
	}

	public List<EagleSecurityMenusXMenu> getParents() {
		return parents;
	}
	
	public void setParents(List<EagleSecurityMenusXMenu> parents) {
		this.parents = parents;
	}


	public void addChild(EagleSecurityMenu child) {
		if (children == null){
			children = new ArrayList<EagleSecurityMenusXMenu>();
		}
		EagleSecurityMenusXMenu menusXMenu = new EagleSecurityMenusXMenu();
		menusXMenu.setChild(child);
		menusXMenu.setParent(this);
		children.add(menusXMenu);
	}
	
	public void addParent(EagleSecurityMenu parent, int position) {
		if (parents == null){
			parents = new ArrayList<EagleSecurityMenusXMenu>();
		}
		EagleSecurityMenusXMenu menusXMenu = new EagleSecurityMenusXMenu();
		EagleSecurityMenusXMenuPK id = new EagleSecurityMenusXMenuPK();
		id.setIdMenuChild(this.getIdmenu());
		id.setIdMenuParent(parent.getIdmenu());
		menusXMenu.setParent(parent);
		menusXMenu.setChild(this);
		menusXMenu.setPk(id);
		menusXMenu.setOrderSeq(new BigDecimal(position));
		parent.addChild(this);
		parents.add(menusXMenu);
	}

}